package com.example.controller;


import com.example.entity.User;
import com.example.mapper.UserMapper;
import com.example.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/getuser")
    @ResponseBody
    public List<User> getPoints() {
        return userMapper.selectList(null);
    }

    @GetMapping("/getToken")
    @ResponseBody
    public Map<String, Object> getToken() {
        Map<String, Object> map = new HashMap<>();

        try {
            Map<String, String> payload = new HashMap<>();
            String token = JWTUtils.getToken(payload);
            map.put("state", true);
            map.put("msg", "登录成功");
            map.put("token", token);
            return map;
        } catch (Exception e) {
            e.printStackTrace();
            map.put("state", false);
            map.put("msg", e.getMessage());
            map.put("token", "");
        }
        return map;
    }

}
